package io.cici.cc.mybatis.plus.core.tagHandler;

import io.cici.cc.mybatis.lite.sql_source.scripting.tag.ForEachTag;
import io.cici.cc.mybatis.lite.sql_source.scripting.tag.MixedTag;
import io.cici.cc.mybatis.lite.sql_source.scripting.tag.Tag;
import io.cici.cc.mybatis.plus.core.MybatisXMLScriptBuilder;

import java.util.List;

public class ForEachHandler implements TagHandler {
    private final MybatisXMLScriptBuilder mybatisXMLScriptBuilder;

    public ForEachHandler(MybatisXMLScriptBuilder mybatisXMLScriptBuilder) {
        this.mybatisXMLScriptBuilder = mybatisXMLScriptBuilder;
        // Prevent Synthetic Access
    }

    @Override
    public void handleNode(io.cici.cc.mybatis.lite.parse.Node nodeToHandle, List<Tag> targetTagList) {
        MixedTag mixedTag = mybatisXMLScriptBuilder.parseDynamicTags(nodeToHandle);
        String collection = MybatisXMLScriptBuilder.cacheStr(nodeToHandle.getStringAttribute("collection"));
        String item = MybatisXMLScriptBuilder.cacheStr(nodeToHandle.getStringAttribute("item"));
        String index = MybatisXMLScriptBuilder.cacheStr(nodeToHandle.getStringAttribute("index"));
        String open = MybatisXMLScriptBuilder.cacheStr(nodeToHandle.getStringAttribute("open"));
        String close = MybatisXMLScriptBuilder.cacheStr(nodeToHandle.getStringAttribute("close"));
        String separator = MybatisXMLScriptBuilder.cacheStr(nodeToHandle.getStringAttribute("separator"));
        ForEachTag forEachTag = new ForEachTag(mybatisXMLScriptBuilder.configuration, mixedTag, collection, index, item, open, close, separator);
        targetTagList.add(forEachTag);
    }
}
